package com.situ.javase.day9;

import java.util.ArrayList;

import org.junit.Test;


public class ArrayListDemo {

	@Test
	public void test1() {
		Student[] students = new Student[3];
		Student student1 = new Student(1, "张三1", 23);
		Student student2 = new Student(2, "张三2", 23);
		Student student3 = new Student(3, "张三3", 23);
		students[0] = student1;
		students[1] = student2;
		students[2] = student3;
		for (int i = 0; i < students.length; i++) {
			System.out.println(students[i]);
		}
		
		for (Student student : students) {
			System.out.println(student);
		}
		
		ArrayList<Student> list = new ArrayList<Student>();
		list.add(student1);
		list.add(student2);
		list.add(student3);
		//list.add(1);
		//list.add("hello")
		
		// 不写<>,代表ArrayList所有类型都可以方法
		ArrayList list2 = new ArrayList();
		list2.add(student1);
		list2.add(1);
		list2.add("hello");
		
		//1、数组方式遍历
		for (int i = 0; i < list.size(); i++) {
			Student student = list.get(i);
			System.out.println(student);
		}
		
		// 2、使用增强的for循环foreach
		for (Student student : list) {
			System.out.println(student);
		}
		
		System.out.println("------------");
		// list2没有指定存放的类型，所以遍历时候拿出的只能是Object类型
		for (Object object : list2) {
			System.out.println(object);
		}
		
		// Object object = student;
		
	}
}
